<?php

namespace app\recharge\controller;

use think\Controller;
use think\Log;
use think\Request;

class Order extends Controller
{

    protected $model;

    public function _initialize()
    {

        //基类授权
        //
        parent::_initialize();
        $this->model = new \app\recharge\model\Order();

        //自定义的初始化
        Log::init([
            'type' => 'File',
            'path' => APP_PATH . 'recharge' . DS . 'logs/',
        ]);
    }

    /**
     * 显示订单列表
     *
     * @return \think\Response
     */
    public function index(Request $request)
    {
        //返回订单列表

        return json($this->model->doList());
    }

    /**
     * 保存新建订单
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {

        //接收请求参数

        $param = $request->param();
        $param = json_encode($param, JSON_UNESCAPED_UNICODE);

        Log::record(json_encode($param, JSON_UNESCAPED_UNICODE), 'info');

        //生成订单数据

        return json($this->model->createOrder($request));
    }

    /**
     * 显示指定的订单
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

}
